<script setup>
import Header from "@/components/common/header/header.vue";
import Footer from "@/components/common/footer/footer.vue";
import {useRoute} from "vue-router";
import {webInfo} from "@/apis/v1/webinfo/webinfo.js";
import {userinfo} from "@/apis/v1/user/login.js";
import {useWebInfo} from "@/store/webinfo.js";
import {useTokenStore, useUserStore} from "@/store/user.js";

const route = useRoute();
const path = ref(null);
watchEffect(() => {
  path.value = route.path;
});
const webStore = useWebInfo();
const userStore = useUserStore();
const tokenStore = useTokenStore();
const getUserInfo = () => {
  userinfo().then(res => {
    if (res.code === 200) {
      userStore.setUser(res.result);
    } else {
      userStore.clearUser();
      tokenStore.clearToken();
    }
  });
};
const getWebInfo = () => {
  webInfo().then(res => {
    if (res.code === 200) {
      webStore.setWebInfo(res.result);
    }
  });
};
onMounted(() => {
  getWebInfo();
  getUserInfo();
});
</script>

<template>
  <Header></Header>
  <router-view></router-view>
  <Footer v-if="path !== '/user/register'
          && path !== '/user/login'
          && path !== '/message'"></Footer>
</template>

<style scoped lang="less">

</style>
